/*
 * CartEvent.java
 * 
 * Created by demory on Mar 30, 2009, 9:35:09 PM
 * 
 * Copyright 2008 David D. Emory
 * 
 * This file is part of Five Points. See <http://www.fpdev.org> for
 * additional information regarding the project.
 * 
 * Five Points is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Five Points is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.fpdev.apps.cart;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author demory
 */
public class CartEvent {

  private Type type_;
  private Editor ed_;
  private Map<String, Object> props_;

  public enum Type {

    FILE_NEW(new CartModule.ID[]{CartModule.ID.FILE}),
    FILE_LOAD(new CartModule.ID[]{CartModule.ID.FILE}),
    FILE_SAVE(new CartModule.ID[]{CartModule.ID.FILE}),
    FILE_SAVE_AS(new CartModule.ID[]{CartModule.ID.FILE}),
    FILE_EXIT(new CartModule.ID[]{CartModule.ID.SYSTEM}),
    FILE_CLEAR_RECENT(new CartModule.ID[]{CartModule.ID.FILE}),

    EDIT_UNDO(new CartModule.ID[]{CartModule.ID.EDITOR}),
    EDIT_REDO(new CartModule.ID[]{CartModule.ID.EDITOR}),
    ZOOM_IN(new CartModule.ID[]{CartModule.ID.EDITOR}),
    ZOOM_OUT(new CartModule.ID[]{CartModule.ID.EDITOR}),

    TOOLS_MOVIE(new CartModule.ID[]{}),
    TOOLS_BUNDLER(new CartModule.ID[]{}),

    CREATE_ANCHOR(new CartModule.ID[]{CartModule.ID.NETWORK}),
    DELETE_ANCHOR(new CartModule.ID[]{CartModule.ID.NETWORK}),
    MOVE_ANCHOR(new CartModule.ID[]{CartModule.ID.NETWORK}),

    CORRIDOR_ENDPOINT(new CartModule.ID[]{CartModule.ID.NETWORK}),
    DELETE_CORRIDOR(new CartModule.ID[]{CartModule.ID.NETWORK}),
    FLIP_CORRIDOR(new CartModule.ID[]{CartModule.ID.NETWORK}),

    CREATE_LINE(new CartModule.ID[]{CartModule.ID.NETWORK}),
    DELETE_LINE(new CartModule.ID[]{CartModule.ID.NETWORK}),
    SET_LINE_STYLE(new CartModule.ID[]{CartModule.ID.NETWORK}),
    MODIFY_LINE(new CartModule.ID[]{CartModule.ID.NETWORK}),
    EDIT_LINE_PROPS(new CartModule.ID[]{CartModule.ID.NETWORK}),

    CREATE_STYLE(new CartModule.ID[]{CartModule.ID.STYLE}),
    DELETE_STYLE(new CartModule.ID[]{CartModule.ID.STYLE}),
    EDIT_STYLE(new CartModule.ID[]{CartModule.ID.STYLE}),
    COPY_STYLE(new CartModule.ID[]{CartModule.ID.STYLE}),

    REFRESH_CANVAS(new CartModule.ID[]{CartModule.ID.EDITOR}),
    MODIFY_EDITOR_PROPERTY(new CartModule.ID[]{CartModule.ID.EDITOR});

    private CartModule.ID[] moduleIDs_;
    //private boolean isAction_;

    /*Type(CartModule.ID[] CartModule.IDs) {
      this(CartModule.IDs, false);
    }*/
    
    Type(CartModule.ID[] moduleIDs) {//, boolean isAction) {
      moduleIDs_ = moduleIDs;
      //isAction_ = isAction;
    }

    public CartModule.ID[] getModuleIDs() {
      return moduleIDs_;
    }

    /*public boolean isAction() {
      return isAction_;
    }*/

  }

  public CartEvent(Type type) {
    this(type, null);
  }

  public CartEvent(Type type, Editor ed) {
    type_ = type;
    ed_ = ed;
    props_ = new HashMap<String, Object>();
  }

  public Type getType() {
    return type_;
  }

  public Editor getEditor() {
    return ed_;
  }

  public void setEditor(Editor ed) {
    ed_ = ed;
  }

  public boolean propertyDefined(String key) {
    return props_.containsKey(key);
  }

  public void setProperty(String key, Object value) {
    props_.put(key, value);
  }

  public Object getProperty(String key) {
    return props_.get(key);
  }

  public String getStringProperty(String key) {
    return props_.get(key).toString();
  }

  public int getIntProperty(String key) {
    return (Integer) props_.get(key);
  }

  public double getDoubleProperty(String key) {
    if(!propertyDefined(key) || !(props_.get(key) instanceof Double)) return 0;
    return (Double) props_.get(key);
  }

}
